export function debounce(that:any,cb:any,time = 300):any{

    let timeout:any = null;
    let callNow = null;

    return function(){
        let args = Array.prototype.slice.call(arguments);
     
        clearTimeout(timeout)
        callNow = !timeout;
        timeout = setTimeout(()=>{
            timeout = null;
        },time);

       
        if (callNow){
           

           
              
              return cb.apply(that,args);
          
        }
        
        return Promise.resolve(null);

        

    }

}

//混入模式
export function mix(...mixins:any) {
    class Mix {
      constructor() {
        for (let mixin of mixins) {
          copyProperties(this, new mixin()); // 拷贝实例属性
        }
      }
    }
  
    for (let mixin of mixins) {
      copyProperties(Mix, mixin); // 拷贝静态属性
      copyProperties(Mix.prototype, mixin.prototype); // 拷贝原型属性
    }
  
    return Mix;
  }
  
function copyProperties(target:any, source:any) {
    for (let key of Reflect.ownKeys(source)) {
      if ( key !== 'constructor'
        && key !== 'prototype'
        && key !== 'name'
      ) {
        let desc:any = Object.getOwnPropertyDescriptor(source, key);
        Object.defineProperty(target, key, desc);
      }
    }
  }
